home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / exec / freepooled.c < prev    next >
C/C++ Source or Header  |  1996-09-12  |  2KB  |  111 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: freepooled.c,v 1.4 1996/08/13 13:56:02 digulla Exp $
  4.     $Log: freepooled.c,v $
  5.     Revision 1.4  1996/08/13 13:56:02  digulla
  6.     Replaced __AROS_LA by __AROS_LHA
  7.     Replaced some __AROS_LH*I by __AROS_LH*
  8.     Sorted and added includes
  9.  
  10.     Revision 1.3  1996/08/01 17:41:11  digulla
  11.     Added standard header for all files
  12.  
  13.     Desc:
  14.     Lang:
  15. */
  16. #include "exec_intern.h"
  17. #include <aros/libcall.h>
  18. #include "machine.h"
  19. #include "memory.h"
  20.  
  21. /*****************************************************************************
  22.  
  23.     NAME */
  24.     #include <exec/memory.h>
  25.     #include <clib/exec_protos.h>
  26.  
  27.     __AROS_LH3(void,FreePooled,
  28.  
  29. /*  SYNOPSIS */
  30.     __AROS_LHA(APTR, poolHeader,A0),
  31.     __AROS_LHA(APTR, memory,    A1),
  32.     __AROS_LHA(ULONG,memSize,   D0),
  33.  
  34. /* LOCATION */
  35.     struct ExecBase *, SysBase, 119, Exec)
  36.  
  37. /*  FUNCTION
  38.     Free memory allocated out of a private memory pool.
  39.  
  40.     INPUTS
  41.     poolHeader - Handle of the memory pool
  42.     memory       - Pointer to the memory
  43.     memSize    - Size of the memory chunk
  44.  
  45.     RESULT
  46.  
  47.     NOTES
  48.  
  49.     EXAMPLE
  50.  
  51.     BUGS
  52.  
  53.     SEE ALSO
  54.     CreatePool(), DeletePool(), AllocPooled()
  55.  
  56.     INTERNALS
  57.  
  58.     HISTORY
  59.     16-10-95    created by M. Fleischer
  60.  
  61. ******************************************************************************/
  62. {
  63.     __AROS_FUNC_INIT
  64.     struct Pool *pool=(struct Pool *)poolHeader;
  65.  
  66.     /* If memSize is bigger than the ThreshSize it's allocated seperately. */
  67.     if(memSize>pool->ThreshSize)
  68.     {
  69.     struct Block *bl;
  70.  
  71.     /* Get pointer to header */
  72.     bl=(struct Block *)((UBYTE *)memory-BLOCK_TOTAL);
  73.  
  74.     /* Remove it from the list */
  75.     Remove((struct Node *)&bl->Node);
  76.  
  77.     /* And Free the memory */
  78.     FreeMem(bl,bl->Size);
  79.     }else
  80.     {
  81.     /* Look for the right MemHeader */
  82.     struct MemHeader *mh=(struct MemHeader *)pool->PuddleList.mlh_Head;
  83.  
  84.     for(;;)
  85.     {
  86.         /* The memory must be between the two borders */
  87.         if(memory>=mh->mh_Lower&&memory<mh->mh_Upper)
  88.         {
  89.         /* Found the MemHeader. Free the memory. */
  90.         Deallocate(mh,memory,memSize);
  91.  
  92.         /* Is this MemHeader completely free now? */
  93.         if(mh->mh_Free==pool->PuddleSize)
  94.         {
  95.             /* Yes. Remove it from the list. */
  96.             Remove(&mh->mh_Node);
  97.  
  98.             /* And free it. */
  99.             FreeMem(mh,pool->PuddleSize+sizeof(struct MemHeader));
  100.         }
  101.         /* All done. */
  102.         break;
  103.         }
  104.         /* Try next MemHeader */
  105.         mh=(struct MemHeader *)mh->mh_Node.ln_Succ;
  106.     }
  107.     }
  108.     __AROS_FUNC_EXIT
  109. } /* FreePooled */
  110.  
  111.